package assignmentstrategy

import (
	"codejy/analysis/codeanalysis"
	"codejy/store"
	"codejy/structdef"
	"strings"
)

type InstancePropStrategy struct {
}

func init() {
	RegisterStrategy(&InstancePropStrategy{})
}
func (n InstancePropStrategy) getId() int {
	return codeanalysis.InstanceProp
}

func (n InstancePropStrategy) Execute(threadStore *structdef.ThreadStore, code string) string {
	index := strings.Index(code, ".")
	v, _, _ := store.Get3LevelVariable(threadStore, code[:index]) //获取变量实例地址
	prop, _ := store.GetInstanceProp(threadStore, v.Value)
	propName := code[index+1:]
	definition, p := prop[propName]
	typeName, _ := prop["@TYPENAME@"] //获取实例的类型名称
	if p {
		return definition.Value
	} else {
		panic("错误::::::" + typeName.Value + "类型中没有" + code + "的成员变量定义")
	}
}
